var app = getApp(), fetchApi = require("../../../utils/httpPost.js"), common_Js = require("../../../component/common.js")
import Toast from '../../../component/vant/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    couponData:[],
    nick_name:'',
    qrcode_id:0,
    use_type:-1,
    isLoading:true,
    qrtype:'',
    band_user_id:0,
    order_info_id:0,
    order:{},
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('validateQr options', options)
    if (options.order_info_id){
      this.data.order_info_id = parseInt(options.order_info_id)
      this.onHttpInit(parseInt(options.order_info_id))
    }
  },
  onHttpInit: function (order_info_id) {
    var that = this
    fetchApi.httpPost('/product/order/orderInfo', {
      info_id: order_info_id,
      reset_qr_code:0,
    }, function (res) {
      console.log("获取二维码数据", res)
      if (res.data.code == 0) {
        that.setData({ 
          order: res.data.data.order,
          orderInfo: res.data.data.orderInfo,
          use_type: res.data.data.use_type,
          nick_name:res.data.data.nickName ,
        })
      }else{
        Toast.fail(res.data.msg)
      }
      that.setData({ netWork: true, isLoading: false, })
    }, function () {
      that.setData({ netWork: false, hasData: false, isLoading: false, })
    })
  },
  handleClick:function(){
    var that = this
    wx.showModal({
      title: '确认核销',
      content: '确认对当前订单进行核销吗？',
      showCancel:true,
      cancelColor:'#333',
      cancelText:'取消',
      confirmColor:'#405f80',
      confirmText:'确认',
      success:function(res){
        console.log('handleClick',res)
        if(res.confirm){
          that.validateCoupon()
        }
      }
    })
  },
  validateCoupon:function(){
    var that = this
    that.setData({ isLoading:true})
    fetchApi.httpPost('/product/order/verifyOrder', {
      order_info_id:that.data.order_info_id
    }, function (res) {
      console.log("核销订单确认信息", res)
      if (res.data.code == 0) {
        Toast.success('核销成功');
        setTimeout(function () {
          wx.navigateBack({
            delta: 1,
          })
        }, 1000)
      } else {
        Toast.fail(res.data.msg)
      }
      that.setData({ netWork: true, isLoading: false, })
    }, function () {
      that.setData({ netWork: false, hasData: false, isLoading: false, })
    })
  },
})